from django.db import models
from thesocialstockmarket.users.models import *
from django.contrib.auth.models import User



#===============================================================================
# PersonalStock: The stocks which are traded by user themselves.
#===============================================================================


class PerStock(Model):
    TYPES = (('0', 'Display'),
             ('1', 'Hide'),)
    user = ForeignKey(User, related_name = '%(class)s_related')
    stock = ForeignKey(Stock,related_name = '%(class)s_related')
    current_hold = FloatField(max_length = 100,default='0')
    display = CharField(max_length=1, choices=TYPES,default='0')
    

class Transactions(Model):
    TYPES = (('B', 'BUY'),
             ('S', 'SELL'),)
    user = ForeignKey(User, related_name = '%(class)s_related')
    stock = ForeignKey(Stock,related_name = 'related_stock')
    type = CharField(max_length=1, choices=TYPES)
    amount = FloatField(max_length = 100)
    date = DateTimeField(auto_now_add=True)
    class Meta:
        get_latest_by = 'date'
#===============================================================================
# PersonalStockRecommendation: a text form for users to write the information  
#about the stock according to PersonalStock table.
#===============================================================================
class PerStockRec(AbstractRec):
    stock = ForeignKey(Stock,related_name = '%(class)s_related')
    per_stock = ForeignKey(PerStock, related_name = '%(class)s_recommendation')
    date = DateTimeField(auto_now_add=True)
    class Meta:
        unique_together = (("per_stock","user"))
        get_latest_by = 'date'
    
#===============================================================================
# FeedBack: feedback for the fluctuation recommendation
#===============================================================================
class PerStockRecRating(AbstractRating):
    per_stock_rec = ForeignKey(PerStockRec, related_name = '%(class)s_rating')
    
    class Meta:
        unique_together = (("per_stock_rec","user"),)